package com.fdy;

import com.alibaba.fastjson.JSON;
import org.fdy.bgadmin.entity.ocr.JsonRootBean;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>描述：</p>
 *
 * @author fangdy
 * @create 2023-12-28 12:53
 */
public class JsonToObject {

    public static void main(String[] args) {
//        String json = "{\"TextDetections\":[{\"DetectedText\":\"<->\",\"Confidence\":100,\"Polygon\":[{\"X\":2098,\"Y\":244},{\"X\":2757,\"Y\":265},{\"X\":2746,\"Y\":619},{\"X\":2087,\"Y\":598}],\"AdvancedInfo\":\"{\\\"Parag\\\":{\\\"ParagNo\\\":2}}\",\"ItemPolygon\":{\"X\":2098,\"Y\":244,\"Width\":659,\"Height\":354},\"Words\":[],\"WordCoordPoint\":[]},{\"DetectedText\":\"OCR文字识别的应用\",\"Confidence\":100,\"Polygon\":[{\"X\":467,\"Y\":665},{\"X\":1655,\"Y\":665},{\"X\":1655,\"Y\":798},{\"X\":467,\"Y\":798}],\"AdvancedInfo\":\"{\\\"Parag\\\":{\\\"ParagNo\\\":1}}\",\"ItemPolygon\":{\"X\":467,\"Y\":665,\"Width\":1188,\"Height\":133},\"Words\":[],\"WordCoordPoint\":[]},{\"DetectedText\":\"OCR\",\"Confidence\":100,\"Polygon\":[{\"X\":2093,\"Y\":750},{\"X\":2751,\"Y\":750},{\"X\":2751,\"Y\":1015},{\"X\":2093,\"Y\":1015}],\"AdvancedInfo\":\"{\\\"Parag\\\":{\\\"ParagNo\\\":3}}\",\"ItemPolygon\":{\"X\":2093,\"Y\":750,\"Width\":658,\"Height\":265},\"Words\":[],\"WordCoordPoint\":[]},{\"DetectedText\":\"及背后技术原理\",\"Confidence\":100,\"Polygon\":[{\"X\":463,\"Y\":894},{\"X\":1375,\"Y\":894},{\"X\":1375,\"Y\":1026},{\"X\":463,\"Y\":1026}],\"AdvancedInfo\":\"{\\\"Parag\\\":{\\\"ParagNo\\\":1}}\",\"ItemPolygon\":{\"X\":463,\"Y\":894,\"Width\":912,\"Height\":132},\"Words\":[],\"WordCoordPoint\":[]}],\"Language\":\"zh\",\"Angel\":359.99,\"PdfPageSize\":0,\"Angle\":359.99,\"RequestId\":\"35a25be4-dcb7-4a11-b8a8-5501fc2cb468\"}\n";
//        JsonRootBean jsonRootBean = JSON.parseObject(json, JsonRootBean.class);
//
//        String toJSONString = JSON.toJSONString(jsonRootBean);
//        System.out.println(toJSONString);
        List<Integer> list = Arrays.asList(9, 10, 55, 100, 156, 200);
        for (int i = 0; i < list.size(); i++) {
            Integer in = list.get(i);
            for (int j = 0; j < in; j++) {
                System.out.println(getFileTempPath("123_"+in, j, in));
            }

        }
    }

    private static String getFileTempPath(String md5, Integer currIndex, Integer totalPieces) {

        int zeroCnt = countDigits(totalPieces) - countDigits(currIndex);
        StringBuilder name = new StringBuilder(md5);
        name.append("/");
        for (int i = 0; i < zeroCnt; i++) {
            name.append(0);
        }
        name.append(currIndex);
        return name.toString();
    }

    private static int countDigits(int number) {
        if (number == 0) {
            return 1;  // 0 本身有一位
        }
        int count = 0;
        while (number != 0) {
            number /= 10;
            count++;
        }
        return count;
    }

}
